package com.avo.ramcache.persist;

import com.avo.ramcache.config.IEntity;

import java.io.Serializable;

public abstract class AbstractListener implements Listener {

    public AbstractListener() {

    }

    @Override
    public void notify(EventType type, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {
        try {
            if (isSuccess) {
                type.successHandle(this, isSuccess, id, entity, exception);
            } else {
                type.errorHandle(this, isSuccess, id, entity, exception);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void onRemoveSuccess(Serializable id) {

    }

    protected void onRemoveError(Serializable id, RuntimeException e) {

    }


    protected void onUpdateSuccess(IEntity<?> entity) {

    }

    protected void onUpdateError(IEntity<?> entity, RuntimeException e) {

    }

    protected void onSaveSuccess(Serializable id, IEntity<?> entity) {

    }

    protected void onSaveError(Serializable id, IEntity<?> entity, RuntimeException e) {

    }

}
